package com.wu.dms.service.impl;


import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wu.dms.cache.UrlCache;
import com.wu.common.convertion.exception.ServiceException;
import com.wu.constant.Enum.MinIoNameEnum;
import com.wu.dms.dao.entity.Banner;
import com.wu.dms.dao.mapper.BannerMapper;
import com.wu.dms.service.BannerService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;



/**
 * @author EDY
 */
@Service
@RequiredArgsConstructor
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {


    @Override
    public Set<String> getAllBannerUrl() {
        List<Banner> bannerList = query().list();
        if(CollectionUtil.isEmpty(bannerList)){
            throw new ServiceException("无海报数据 请及时更新");
        }
        return bannerList.stream().map(banner -> UrlCache.getUrl(MinIoNameEnum.BANNER_IMAGE.getBucketName(), banner.getId(), banner.getPic())).collect(Collectors.toSet());
    }
}
